home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13329 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: niamh.indigo.ie!usenet
  2. From: nsmart@indigo.ie (Niall Smart)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Settle a bet please
  5. Date: Fri, 05 Apr 1996 20:04:40 GMT
  6. Organization: None
  7. Message-ID: <4k41v6$60v@niamh.indigo.ie>
  8. References: <4jfopb$o9n@news1.sympatico.ca> <Dp11Bx.2o7@watserv3.uwaterloo.ca>
  9. NNTP-Posting-Host: dublin-ts7-156.indigo.ie
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. bcrwhims@uwaterloo.ca  (Carsten Whimster) wrote:
  13.  
  14. [snip]
  15.  
  16. >   int i; char Name[7] = "My Name";
  17. >   char More[]  = "AAAAAAA";
  18.  
  19. >   for (i = 0; Name[i] != '\0'; i++)
  20. >      putchar(Name[i]);
  21.  
  22. >If you loop until you see a NULL, you might get "My NameAAAAAAA". There
  23. >may be some compiler variation there, but I am not sure about those. 
  24. >I am only recently getting relatively familiar with C as a language, 
  25. >never mind the platform dependencies. Actually, on my machine (OS/2 and 
  26. >IBM VAC++), it prints out:
  27.  
  28. >My Name\à
  29.  
  30. >So obviously a NULL is needed. Interestingly, the "AAAAAAA" string is 
  31. >not placed right after the Name string on my machine. Does anyone know 
  32. >what the compiler might be doing here?
  33.  
  34. char* More[] points to read-only memory containing "AAAAAAA", if you
  35. try to change what More is pointing to then the behaviour is
  36. undefined. The compiler is probably putting the "AAAAAAA" in a
  37. different data space because it is ROM.
  38.  
  39. Niall
  40.  
  41.  
  42.